package org.cs.mainmemorymachine;

import java.util.LinkedList;
import java.util.List;

/**
 * 存储体 MB
 *
 * @author fbin
 * @since 2022/4/5 10:46
 */
public class MemoryBody {
    /**
     * 最大存储记录数
     */
    private static final int MAX_RECORDS = 100000;

    /**
     * 主存储体
     */
    private static final Object[] MAIN_MEMORY;

    static {
        MAIN_MEMORY = new Object[MAX_RECORDS];
    }

    /**
     * 读取数据
     *
     * @param address 地址
     * @return 数据
     */
    public Object getData(int address) {
        if (address >= MAX_RECORDS) {
            throw new RuntimeException("address out of max memory limit.");
        }
        return MAIN_MEMORY[address];
    }

    /**
     * 写入数据
     *
     * @param address 地址
     * @param data    数据
     */
    public void setData(int address, Object data) {
        MAIN_MEMORY[address] = data;
    }
}
